package com.mingtu.jgspatrol.activity;

import static com.mingtu.common.utils.MyUtills.getBounds;
import static com.mingtu.jgspatrol.utils.MyConstant.INFO_WINDOW_OFF_SET_Y;
import static com.mingtu.jgspatrol.utils.MyConstant.MAX_ZOOM;

import android.animation.ValueAnimator;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.Polygon;
import com.amap.api.maps.model.PolygonOptions;
import com.amap.api.maps.model.Polyline;
import com.amap.api.maps.model.PolylineOptions;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.StringUtils;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.hjq.gson.factory.GsonFactory;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.mingtu.common.activity.NaviMapActivity;
import com.mingtu.common.base.BaseBindingActivity;
import com.mingtu.common.callback.StringDialogCallback;
import com.mingtu.common.utils.Constant;
import com.mingtu.common.utils.ConvertLatlng;
import com.mingtu.common.utils.IntentUtils;
import com.mingtu.common.utils.MyLogUtil;
import com.mingtu.common.utils.SPTools;
import com.mingtu.common.utils.StatusBarUtil;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.bean.GridResBean;
import com.mingtu.jgspatrol.bean.MyGridInfoBean;
import com.mingtu.jgspatrol.databinding.ActivityChargeAreaBinding;
import com.mingtu.jgspatrol.utils.MarkerOptionsUtils;
import com.mingtu.jgspatrol.utils.MyConstant;
import com.mingtu.infrared.bean.InfraredBubbleInfoBean;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ChargeAreaActivity extends BaseBindingActivity<ActivityChargeAreaBinding> implements AMap.OnMarkerClickListener,
        AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener {

    private AMap aMap;
    private MapView mapView;
    private MyGridInfoBean.GridInfoBean gridInfoBean;
    private String duty;
    private List<Polygon> polygonList = new ArrayList<>();
    private List<Polyline> polylineList = new ArrayList<>();
    private List<Marker> markerList = new ArrayList<>();
    private List<GridResBean.DataBean.CameraListBean> cameraListBeans;
    private List<GridResBean.DataBean.IrCameraListBean> irCameraListBeans;
    private View infoWindow;
    private LatLng location;
    private List<LatLng> allLatLngs = new ArrayList<>();
    private String[] markerType = {"1", "2"};

    @Override
    protected int getLayoutId() {
        return R.layout.activity_charge_area;
    }

    @Override
    protected void initView() {
        setDarkThemeStatusBar();
        setModuleTitle("林长网格");
    }

    @Override
    protected void initData() {
        binding.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_but1: //网格信息
                        showModle(1);
                        break;
                    case R.id.rb_but2://工作信息
                        showModle(2);
                        break;
                    case R.id.rb_but3://工作职责
                        showModle(3);
                        break;
                    case R.id.rb_but4://资源展示
                        showModle(4);
                        break;

                }
            }
        });
        binding.ivJobInfo.setImage(ImageSource.resource(R.mipmap.img_job_info));

        addClickListener(this, binding.checkZoom);
    }

    @Override
    protected void getData() {

    }

    @Override
    protected void initMap(Bundle savedInstanceState) {
        super.initMap(savedInstanceState);
        mapView = findViewById(R.id.mapView);
        mapView.onCreate(savedInstanceState);
        aMap = mapView.getMap();
        //地图模式可选类型：MAP_TYPE_NORMAL,MAP_TYPE_SATELLITE,MAP_TYPE_NIGHT
        aMap.setMapType(AMap.MAP_TYPE_NORMAL);// 矢量地图模式
        aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
        aMap.getUiSettings().setZoomControlsEnabled(false);
        aMap.setOnMarkerClickListener(this);
        aMap.setInfoWindowAdapter(this);
        aMap.setOnInfoWindowClickListener(this);
        aMap.setMaxZoomLevel(MAX_ZOOM);
        aMap.moveCamera(CameraUpdateFactory.zoomTo(Constant.MAP_ZOOM_TWO));
        aMap.setOnMapLoadedListener(new AMap.OnMapLoadedListener() {
            @Override
            public void onMapLoaded() {
                getGridInfo();
                getGridResource();
            }
        });
        String longitude = SPStaticUtils.getString(SPTools.lng);
        String latitude = SPStaticUtils.getString(SPTools.lat);
        if (!StringUtils.isEmpty(longitude) && !StringUtils.isEmpty(latitude)) {
            location = new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude));
            //添加Marker
            MarkerOptions markerOptions = new MarkerOptions()
                    .position(location)
                    .icon(BitmapDescriptorFactory.fromResource(com.mingtu.home.R.mipmap.sb_icon_wz))
                    .infoWindowEnable(false);
            Marker marker = aMap.addMarker(markerOptions);
            markerList.add(marker);
            aMap.moveCamera(CameraUpdateFactory.changeLatLng(location));
        }
    }

    @Override
    protected void onDestroy() {
        if (aMap != null) {
            mapView.onDestroy();
        }

        if (polygonList.size() > 0) {
            for (Polygon polygon : polygonList) {
                polygon.remove();
            }
            polygonList.clear();
        }

        if (polylineList.size() > 0) {
            for (Polyline polyline : polylineList) {
                polyline.remove();
            }
            polylineList.clear();
        }

        if (markerList.size() > 0) {
            for (Marker marker : markerList) {
                marker.remove();
            }
            markerList.clear();
        }

        super.onDestroy();
    }

    /**
     * 获取责任区相关信息
     */
    private void getGridInfo() {
        OkGo.<String>post(MyConstant.POST_GRID_INFO)
                .tag(this)
                .upJson("")
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        if (!StringUtils.isEmpty(result)) {
                            try {
                                Gson gson = GsonFactory.getSingletonGson();
                                MyGridInfoBean dutyInfoBean = new MyGridInfoBean();
                                dutyInfoBean = gson.fromJson(result, MyGridInfoBean.class);
                                List<MyGridInfoBean.GridInfoBean> gridInfoBeans = dutyInfoBean.getGridInfo();
                                if (gridInfoBeans != null) {
                                    if (gridInfoBeans.size() > 0) {
                                        gridInfoBean = gridInfoBeans.get(0);
                                        if (gridInfoBean != null) {
                                            duty = gridInfoBean.getDuty(); //工作职责
                                            String no = gridInfoBean.getNo();//编号
                                            String name = gridInfoBean.getName();//区划域名
                                            String userName = gridInfoBean.getUserName();//负责人
                                            String mobile = gridInfoBean.getMobile();
                                            String dept = gridInfoBean.getDept();

                                            if (!StringUtils.isEmpty(no)) {
                                                binding.tvNo.setText("责任区编号：" + no);
                                            }

                                            if (!StringUtils.isEmpty(name)) {
                                                binding.tvAreaName.setText("当前区划区域名：" + name);
                                            }

                                            if (!StringUtils.isEmpty(dept)) {
                                                binding.tvDept.setText(dept);
                                            }


                                            if (!StringUtils.isEmpty(userName)) {
                                                binding.tvUserName.setText(userName);
                                            }

                                            if (!StringUtils.isEmpty(mobile)) {
                                                binding.tvTel.setText(mobile);
                                            }

                                            if (!StringUtils.isEmpty(duty)) {
                                                String s = duty.replace("\\n", "\n");
                                                String s1 = s.replace("\\u3000", "\u3000");
                                                binding.tvContent.setText(s1);
                                            }

                                        }

                                        String myArea = "0";
                                        //责任区域及面积
                                        for (int j = 0; j < gridInfoBeans.size(); j++) {
                                            MyGridInfoBean.GridInfoBean gridInfoBean = gridInfoBeans.get(j);
                                            BigDecimal area = new BigDecimal(gridInfoBean.getArea());
                                            String points = gridInfoBean.getPoints().replaceAll(" ", "");
                                            myArea = new BigDecimal(myArea).add(area).doubleValue() + "";

                                            if (points.length() > 0) {
                                                List<LatLng> latLngs = new ArrayList<>();
                                                MyLogUtil.e("points", "points length=" + points.length() + "," + (points.length() - 3));
                                                String MyPoints = points.substring(3, points.length() - 3);
                                                if (MyPoints.indexOf("，") != -1) {
                                                    //含有中文符号的时候把中文逗号换成英文逗号
                                                    MyPoints = MyPoints.replaceAll("，", ",");
                                                }
                                                String[] objectsArray1 = MyPoints.split("],\\[");
                                                for (int i = 0; i < objectsArray1.length; i++) {
                                                    String[] objectsArray2 = objectsArray1[i].split(",");
                                                    double lng = Double.parseDouble(objectsArray2[0]);
                                                    double lat = Double.parseDouble(objectsArray2[1]);
                                                    LatLng latLng = new LatLng(lat, lng);
                                                    latLngs.add(latLng);
                                                    allLatLngs.add(latLng);
                                                }
                                                PolygonOptions polygonOptions = new PolygonOptions();
                                                polygonOptions.addAll(latLngs);
                                                polygonOptions.strokeWidth(2);
                                                polygonOptions.fillColor(context.getResources().getColor(R.color.bg_color_1f1e9));
                                                polygonOptions.strokeColor(context.getResources().getColor(R.color.bg_color_1f1e9));
                                                Polygon mapPolygon = aMap.addPolygon(polygonOptions);
                                                polygonList.add(mapPolygon);
//                                        aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getBounds(latLngs), 200));

                                                Polyline mapPolyline = aMap.addPolyline(new PolylineOptions()
                                                        .addAll(latLngs)
                                                        .width(8)
                                                        .zIndex(100)
                                                        .setDottedLine(true)
                                                        .setDottedLineType(PolylineOptions.DOTTEDLINE_TYPE_SQUARE)
                                                        .color(context.getResources().getColor(R.color.colorPrimary)));
                                                polylineList.add(mapPolyline);
                                            }

                                        }

                                        if (!StringUtils.isEmpty(myArea)) {
//                                                double myArea = Double.parseDouble(area) / 1000 * 1000;
                                            BigDecimal b1 = new BigDecimal(myArea);
                                            BigDecimal b2 = new BigDecimal((1000 * 1000) + "");

                                            binding.tvArea.setText(b1.divide(b2, 2) + "k㎡");
                                        }
                                    }
                                }


                            } catch (JsonSyntaxException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                });
    }

    private void showModle(int i) {
        switch (i) {
            case 1:
                binding.layout1.setVisibility(View.VISIBLE);
                binding.layout2.setVisibility(View.GONE);
                binding.layout3.setVisibility(View.GONE);
                binding.layout4.setVisibility(View.GONE);
                break;
            case 2:
                binding.layout1.setVisibility(View.GONE);
                binding.layout2.setVisibility(View.VISIBLE);
                binding.layout3.setVisibility(View.GONE);
                binding.layout4.setVisibility(View.GONE);
                break;
            case 3:
                binding.layout1.setVisibility(View.GONE);
                binding.layout2.setVisibility(View.GONE);
                binding.layout3.setVisibility(View.VISIBLE);
                binding.layout4.setVisibility(View.GONE);
                break;
            case 4:
                binding.layout1.setVisibility(View.GONE);
                binding.layout2.setVisibility(View.GONE);
                binding.layout3.setVisibility(View.GONE);
                binding.layout4.setVisibility(View.VISIBLE);
                break;
        }
    }

    /**
     * 网格资源
     */
    private void getGridResource() {
        OkGo.<String>post(MyConstant.POST_GRID_RESOURCE)
                .tag(this)
                .upJson("")
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        if (!StringUtils.isEmpty(result)) {
                            try {
                                Gson gson = GsonFactory.getSingletonGson();
                                GridResBean gridResBean = new GridResBean();
                                gridResBean = gson.fromJson(result, GridResBean.class);
                                GridResBean.DataBean dataBean = gridResBean.getData();
                                if (dataBean != null) {
                                    cameraListBeans = dataBean.getCameraList();
                                    irCameraListBeans = dataBean.getIrCameraList(); //红外


                                    //监控摄像头
                                    if (cameraListBeans != null) {
                                        int size = cameraListBeans.size();
                                        binding.tvCameraNum.setText(size + "");
                                        if (size > 0) {
                                            for (int i = 0; i < size; i++) {
                                                GridResBean.DataBean.CameraListBean cameraListBean = cameraListBeans.get(i);
                                                String latitude = cameraListBean.getLat();
                                                String longitude = cameraListBean.getLng();
                                                String updateTime = cameraListBean.getUpdateTime();
                                                String deptName = cameraListBean.getDeptName();
                                                String gridId = cameraListBean.getGridId();
                                                if (!StringUtils.isEmpty(latitude) && !StringUtils.isEmpty(longitude)) {
                                                    double lat = Double.parseDouble(latitude);
                                                    double lng = Double.parseDouble(longitude);
                                                    int status = cameraListBean.getStatus();
                                                    String cameraName = cameraListBean.getName();
                                                    String cameraType = cameraListBean.getType();

                                                    String myLng = ConvertLatlng.getInstance().convertToSexagesimal(lng);
                                                    String myLat = ConvertLatlng.getInstance().convertToSexagesimal(lat);

                                                    HashMap<String, Object> myHashMap = new HashMap<>();
                                                    myHashMap.put("cameraName", cameraName);
                                                    myHashMap.put("status", status);
                                                    myHashMap.put("cameraType", cameraType);
                                                    myHashMap.put("updateTime", updateTime);
                                                    myHashMap.put("deptName", deptName); //此处是所属保护站
                                                    myHashMap.put("picCount", gridId + "");
                                                    myHashMap.put("location", myLat + "," + myLng);
                                                    myHashMap.put("lat", lat + "");
                                                    myHashMap.put("lng", lng + "");
                                                    myHashMap.put("myType", markerType[1]);//监控摄像头
                                                    String infraredInfo = GsonUtils.toJson(myHashMap);
                                                    LatLng location = new LatLng(lat, lng);
                                                    allLatLngs.add(location);

                                                    //添加Marker
                                                    if (status == 1) {
                                                        MarkerOptions markerOptions = new MarkerOptions()
                                                                .position(location)
                                                                .title(infraredInfo)
                                                                .anchor(0.5f, 0.8f)
                                                                .icon(BitmapDescriptorFactory.fromResource(R.mipmap.icon_camera_online));
                                                        Marker marker = aMap.addMarker(markerOptions);
                                                        markerList.add(marker);
                                                    } else if (status == 0) {
                                                        MarkerOptions markerOptions = new MarkerOptions()
                                                                .position(location)
                                                                .title(infraredInfo)
                                                                .anchor(0.5f, 0.8f)
                                                                .icon(BitmapDescriptorFactory.fromResource(R.mipmap.icon_camera_offline));
                                                        Marker marker = aMap.addMarker(markerOptions);
                                                        markerList.add(marker);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    //红外相机
                                    if (irCameraListBeans != null) {
                                        int size = irCameraListBeans.size();
                                        binding.tvInfraredNum.setText(size + "");
                                        if (size > 0) {
                                            ArrayList<BitmapDescriptor> giflist = new ArrayList<BitmapDescriptor>();
                                            ApplicationInfo appInfo = getApplicationInfo();
                                            for (int i = 1; i <= 24; i++) {
                                                int resID = getResources().getIdentifier("icon_infrared" + i, "mipmap", appInfo.packageName);
                                                giflist.add(BitmapDescriptorFactory.fromResource(resID));
                                            }

                                            for (int i = 0; i < size; i++) {
                                                GridResBean.DataBean.IrCameraListBean irCameraListBean = irCameraListBeans.get(i);
                                                String latitude = irCameraListBean.getLatitude();
                                                String longitude = irCameraListBean.getLongitude();

                                                if (!StringUtils.isEmpty(latitude) && !StringUtils.isEmpty(longitude)) {
                                                    String cameraName = irCameraListBean.getCameraName();
                                                    String cameraCode = irCameraListBean.getCameraCode();
                                                    String updateTime = irCameraListBean.getUpdateTime();
                                                    int status = irCameraListBean.getStatus();
                                                    String picCount = irCameraListBean.getPicCount();
                                                    int batteryLevel = irCameraListBean.getBatteryLevel();

                                                    double lat = Double.parseDouble(latitude);
                                                    double lng = Double.parseDouble(longitude);
                                                    String myLng = ConvertLatlng.getInstance().convertToSexagesimal(lng);
                                                    String myLat = ConvertLatlng.getInstance().convertToSexagesimal(lat);


                                                    HashMap<String, Object> myHashMap = new HashMap<>();
                                                    myHashMap.put("cameraName", cameraName);
                                                    myHashMap.put("cameraCode", cameraCode);
                                                    myHashMap.put("updateTime", updateTime);
                                                    myHashMap.put("batteryLevel", batteryLevel);
                                                    myHashMap.put("status", status);
                                                    myHashMap.put("picCount", picCount + "");
                                                    myHashMap.put("location", myLat + "," + myLng);
                                                    myHashMap.put("lat", lat + "");
                                                    myHashMap.put("lng", lng + "");
                                                    myHashMap.put("myType", markerType[0]); //红外相机
                                                    String infraredInfo = GsonUtils.toJson(myHashMap);
                                                    LatLng location = new LatLng(lat, lng);
                                                    allLatLngs.add(location);

                                                    //添加Marker
                                                    if (status == 1) {
                                                        Marker marker = aMap.addMarker(MarkerOptionsUtils.getMarkerOptions2(location, infraredInfo, INFO_WINDOW_OFF_SET_Y, giflist));
                                                        markerList.add(marker);
                                                    } else if (status == 0) {
                                                        Marker marker = aMap.addMarker(MarkerOptionsUtils.getMarkerOptions1(location, infraredInfo, INFO_WINDOW_OFF_SET_Y, R.mipmap.icon_infrared_offline));
                                                        markerList.add(marker);
                                                    }

                                                }
                                            }
                                        }
                                    }

                                    aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getBounds(allLatLngs), 200));
                                }
                            } catch (JsonSyntaxException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                });
    }


    @Override
    public View getInfoWindow(Marker marker) {
//        if (infoWindow == null) {
//            infoWindow = LayoutInflater.from(this).inflate(R.layout.infrared_bubble_view, null);
//        }


        String infraredInfo = marker.getTitle();
        InfraredBubbleInfoBean infraredBubbleInfoBean = null;
        try {
            Gson gson = GsonFactory.getSingletonGson();
            infraredBubbleInfoBean = new InfraredBubbleInfoBean();
            infraredBubbleInfoBean = gson.fromJson(infraredInfo, InfraredBubbleInfoBean.class);
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        String myType = infraredBubbleInfoBean.getMyType();
        if (myType.equals(markerType[0])) {
            infoWindow = LayoutInflater.from(this).inflate(R.layout.infrared_bubble_view, null);
        } else if (myType.equals(markerType[1])) {
            infoWindow = LayoutInflater.from(this).inflate(R.layout.camera_bubble_view, null);
        }
        return render(infraredBubbleInfoBean, infoWindow);
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }

    @Override
    public void onInfoWindowClick(Marker marker) {
        marker.hideInfoWindow();
    }

    @Override
    public boolean onMarkerClick(Marker marker) {
        marker.showInfoWindow();
        return false;
    }

    /**
     * 自定义infowinfow窗口
     */
    public View render(InfraredBubbleInfoBean infraredBubbleInfoBean, View view) {

        String cameraName = infraredBubbleInfoBean.getCameraName();
        String cameraCode = infraredBubbleInfoBean.getCameraCode();
        String updateTime = infraredBubbleInfoBean.getUpdateTime();
        int batteryLevel = infraredBubbleInfoBean.getBatteryLevel();
        int status = infraredBubbleInfoBean.getStatus();
        String picCount = infraredBubbleInfoBean.getPicCount();
        String location = infraredBubbleInfoBean.getLocation();
        String myType = infraredBubbleInfoBean.getMyType();
        String deptName = infraredBubbleInfoBean.getDeptName();
        String cameraType = infraredBubbleInfoBean.getCameraType();
        String latStr = infraredBubbleInfoBean.getLat();
        String lngStr = infraredBubbleInfoBean.getLng();

        LinearLayout layoutStatus = (LinearLayout) view.findViewById(R.id.layout_status);
        TextView tvName = (TextView) view.findViewById(R.id.tv_name);
        TextView tvCode = (TextView) view.findViewById(R.id.tv_code);
        TextView tvTime = (TextView) view.findViewById(R.id.tv_time);
        TextView tvElectric = (TextView) view.findViewById(R.id.tv_electric);
        TextView tvStatus = (TextView) view.findViewById(R.id.tv_status);
        TextView tvNum = (TextView) view.findViewById(R.id.tv_num);
        TextView tvLocation = (TextView) view.findViewById(R.id.tv_location);

        TextView tvNvi = (TextView) view.findViewById(R.id.tv_nvi);
        tvNvi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("lng", lngStr);
                bundle.putString("lat", latStr);
                bundle.putBoolean("isFire", false);
                IntentUtils.getInstance().readyGo(ChargeAreaActivity.this, NaviMapActivity.class, bundle);
            }
        });


        if (!StringUtils.isEmpty(cameraName)) {
            tvName.setText(cameraName);
        }

        if (!StringUtils.isEmpty(updateTime)) {
            tvTime.setText(updateTime);
        }

        if (!StringUtils.isEmpty(picCount)) {
            tvNum.setText(picCount);
        }
        if (!StringUtils.isEmpty(location)) {
            tvLocation.setText(location);
        }

        if (myType.equals(markerType[0])) {
            tvElectric.setText(batteryLevel * 10 + "%");
            if (batteryLevel <= MyConstant.BATTERY_WARNIG_LEVEEL) {
                tvElectric.setTextColor(getResources().getColor(R.color.text_color_fec));
            } else {
                tvElectric.setTextColor(getResources().getColor(R.color.colorPrimary));
            }

            if (!StringUtils.isEmpty(cameraCode)) {
                tvCode.setText(cameraCode);
            }

        } else if (myType.equals(markerType[1])) {
            tvElectric.setText(deptName + "");
            if (!StringUtils.isEmpty(cameraType)) {
                tvCode.setText(cameraType);
            }
        }

        if (myType.equals(markerType[0])) {
            //红外
            if (status == 1) {
                tvStatus.setText("在线");
                layoutStatus.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
            } else if (status == 2) {
                tvStatus.setText("离线");
                layoutStatus.setBackgroundColor(getResources().getColor(R.color.bg_color_e45));
            }
        } else if (myType.equals(markerType[1])) {
            //摄像头
            if (status == 1) {
                tvStatus.setText("在线");
                layoutStatus.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
            } else if (status == 0) {
                tvStatus.setText("离线");
                layoutStatus.setBackgroundColor(getResources().getColor(R.color.bg_color_e45));
            }
        }
        return view;
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.check_zoom:

                boolean isChecked = binding.checkZoom.isChecked();

                int maxHeight = 0;
                if (topTitlebarBaseBinding.clTitlebar != null) {
                    maxHeight = ScreenUtils.getScreenHeight() - (StatusBarUtil.getStatusBarHeight(context) + SizeUtils.getMeasuredHeight(topTitlebarBaseBinding.clTitlebar));
                } else {
                    maxHeight = ScreenUtils.getScreenHeight() - (StatusBarUtil.getStatusBarHeight(context) + SizeUtils.dp2px(44));

                }
                if (!isChecked) {
                    //缩小
                    binding.checkZoom.setChecked(false);
                    binding.layoutInfo.setVisibility(View.VISIBLE);
                    ViewGroup.LayoutParams layoutParams = (ViewGroup.LayoutParams) binding.layoutMap.getLayoutParams();
                    layoutParams.width = ScreenUtils.getScreenWidth();
                    layoutParams.height = SizeUtils.getMeasuredHeight(binding.viewBlock);
                    binding.layoutMap.setLayoutParams(layoutParams);
                    changeViewHeightAnimatorStart(binding.layoutMap, maxHeight, SizeUtils.getMeasuredHeight(binding.viewBlock));

                } else {
                    //放大
                    binding.checkZoom.setChecked(true);
                    binding.layoutInfo.setVisibility(View.GONE);
                    ViewGroup.LayoutParams layoutParams = (ViewGroup.LayoutParams) binding.layoutMap.getLayoutParams();
                    layoutParams.width = ScreenUtils.getScreenWidth();

                    layoutParams.height = maxHeight;
                    binding.layoutMap.setLayoutParams(layoutParams);

                    Animation alphaAnim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.map_anim_scale_in);
                    binding.layoutMap.startAnimation(alphaAnim);
                }

                break;
        }
    }

    public static void changeViewHeightAnimatorStart(final View view, final int startHeight, final int endHeight) {

        if (view != null && startHeight >= 0 && endHeight >= 0) {

            ValueAnimator animator = ValueAnimator.ofInt(startHeight, endHeight);
            animator.setDuration(300);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    ViewGroup.LayoutParams params = view.getLayoutParams();
                    params.height = (int) animation.getAnimatedValue();
                    params.width = ScreenUtils.getScreenWidth();
                    view.setLayoutParams(params);
                }
            });
            animator.start();
        }

    }

}